package com.hlbbcsr.dao.impl;

import java.util.List;

import com.hlbbcsr.dao.CustomerDAO;
import com.hlbbcsr.domain.bean.Customer;

public class CustomerDAOImpl extends BaseHelperDAO implements CustomerDAO {

	public static final String CUSTOMER_NAME	= "customerName";
	public static final String LOGIN_ID 	 	= "loginId";

	public List<Customer> findByCustomerName(Object customerName) throws Exception {
		return findByProperty(CUSTOMER_NAME, customerName);
	}
	
	public List<Customer> findByLoginId(Object loginId) throws Exception {
		return findByProperty(LOGIN_ID, loginId);
	}
	
	@SuppressWarnings("unchecked")
	public List<Customer> findByProperty(String propertyName, Object value) throws Exception {

		try {

			String queryString = "from Customer as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);

		} catch (RuntimeException re) {
			throw re;
		}
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Customer> listCgsCustomer() throws Exception {
		List<Customer> result = null;
		
		String queryString = "from Customer";
		result = getHibernateTemplate().find(queryString);
		
		return result;
	}
	
	public void addCustomer(Customer entity) throws Exception {
		getHibernateTemplate().save(entity);
	}
}